
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>  /* varargs */
#include <syslog.h>
#include "tp_debug.h"

#define SYSTEM(cmd) system(cmd)

void print_log(const char *fmt, ...)
{
  char buf[1024];

  va_list args;
  va_start( args, fmt );
  vsnprintf(buf, sizeof(buf), fmt,args);
  va_end( args );

  printf("%s\n", buf);

  FILE *logfile = fopen("./gw.log", "ab");
  if (logfile == NULL)
    return;
  fwrite(buf, 1, strlen(buf), logfile);
  fclose(logfile);
}

int execute_command(const char *fmt, ...)
{  
  char buf[256];  
  va_list args;  
  va_start( args, fmt );  
  vsnprintf(buf, sizeof(buf), fmt,args);  
  va_end( args );  
  LOG ("execute: %s\n", buf);  
  return SYSTEM (buf);  
}


 
